package com.example.peng.myokhttpfinal;

import android.content.Context;
import android.text.TextUtils;
import android.widget.Toast;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by EricYuan on 2017/3/9.
 */

public class StringDela {
    /**
     * 判断是否为空
     */
    public static boolean isNull(String str) {
        if (TextUtils.isEmpty(str))
            return true;
        if ("null".equals(str))
            return true;
        if (null == str)
            return true;
        return false;
    }

    public static void showToast(Context context, String message) {
        if (!isNull(message))
            Toast.makeText(context, message, Toast.LENGTH_SHORT).show();
    }

    /**
     *
     * @param phone 检查手机号码是否输入正确
     * @return
     */
    public static boolean checkPhoneNum(String phone) {
        Pattern p = Pattern.compile("^[1][34578]\\d{9}$");
        if (p != null) {
            Matcher matcher = p.matcher(phone);
            if (matcher.find()) {
                return true;
            }
        }
        return false;
    }
}
